package com.huaxin.hxmodulesystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaxin.hxmodulesystem.dto.ResponseCode;
import com.huaxin.hxmodulesystem.dto.ResponseResult;
import com.huaxin.hxmodulesystem.dto.request.AddElectricianArchiveAuditRecordReqDTO;
import com.huaxin.hxmodulesystem.mapper.ElectricianArchiveAuditRecordMapper;
import com.huaxin.hxmodulesystem.mapping.ElectricianArchiveAuditRecordMapping;
import com.huaxin.hxmodulesystem.models.ElectricianArchiveAuditRecord;
import com.huaxin.hxmodulesystem.service.ElectricianArchiveAuditRecordService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ElectricianArchiveAuditRecordServiceImpl extends ServiceImpl<ElectricianArchiveAuditRecordMapper, ElectricianArchiveAuditRecord> implements ElectricianArchiveAuditRecordService {
    private final ApplicationContext applicationContext;
    private final ElectricianArchiveAuditRecordMapping electricianArchiveAuditRecordMapping;

    /**
     * 添加电工档案审核记录
     *
     * @param in
     * @return
     */
    @Override
    public ResponseResult<ElectricianArchiveAuditRecord> addElectricianArchiveAuditRecord(AddElectricianArchiveAuditRecordReqDTO in) {
        if (in == null) {
            return ResponseResult.parameterError(null, "参数错误");
        }
        if (StringUtils.isBlank(in.getElectricianArchiveId())) {
            return ResponseResult.parameterError(null, "电工档案ID不能为空");
        }

        ElectricianArchiveAuditRecord entity = electricianArchiveAuditRecordMapping.toEntity(in);
        if (this.save(entity)) {
            return ResponseResult.ok(entity);
        } else {
            return ResponseResult.failure(ResponseCode.INTERNAL_ERROR, "添加失败，请稍后再试！", null);
        }
    }
}
